package com.edushare.common.file.image;

public class ImageSpec {
	
	//Rule 1: Always resize before crop
	//Rule 2: Dont resize, and hence crop, if image size < width x height
	public static final int CROP_TO_DIMENSION = 1;
	public static final int BEST_FIT = 2;
	public static final int FIXED_HEIGHT = 3;
	public static final int FIXED_WIDTH = 4;
	public static final int FORCE_RESIZE = 5;
	
	private int width = 0;
	private int height = 0;
	private int resizeMechanism = BEST_FIT;
	private String suffix;
	
	/**
	 * Resizes Image to this rectangle.
	 * <b>NOTE!</b>
	 * <p>This May Result in Distorted Image.
	 * @param width
	 * @param height
	 */
	/*public  static ImageSpec instanceByForceResize(int width, int height){
		ImageSpec is = new ImageSpec();
		is.setWidth(width);
		is.setHeight(height);
		is.setResizeMechanism(FORCE_RESIZE);
		return is;
	}*/
	
	private ImageSpec(){}
	
	/**
	 * Resize by keeping height fixed and width as per original aspect ratio
	 * @param height
	 * @return
	 */
	public static ImageSpec instanceByHeight(int height){
		ImageSpec is = new ImageSpec();
		is.setHeight(height);
		is.setResizeMechanism(FIXED_HEIGHT);
		return is;
	}
	
	/**
	 * Resize by keeping width fixed and height as per original aspect ratio
	 * @param width
	 * @return
	 */
	public static ImageSpec instanceByWidth(int width){
		ImageSpec is = new ImageSpec();
		is.setWidth(width);
		is.setResizeMechanism(FIXED_WIDTH);
		return is;
	}
	
	/**
	 * Resize image to fit in given rectangular area without changing the aspect ratio
	 * @param maxWidth
	 * @param MaxHeight
	 * @return
	 */
	public static ImageSpec instanceByFitInRectangle(int maxWidth, int maxHeight){
		ImageSpec is = new ImageSpec();
		is.setWidth(maxWidth);
		is.setHeight(maxHeight);
		is.setResizeMechanism(BEST_FIT);
		return is;
	}
	
	public static ImageSpec instanceByFillInRectangle(int width, int height){
		ImageSpec is = new ImageSpec();
		is.setWidth(width);
		is.setHeight(height);
		is.setResizeMechanism(CROP_TO_DIMENSION);
		return is;
	}
	
	//getters,setters
	public int getWidth() {
		return width;
	}
	public void setWidth(int width) {
		this.width = width;
	}
	public int getHeight() {
		return height;
	}
	public void setHeight(int height) {
		this.height = height;
	}

	public void setSuffix(String suffix) {
		this.suffix = suffix;
	}

	public String getSuffix() {
		return suffix;
	}

	public void setResizeMechanism(int resizeMechanism) {
		this.resizeMechanism = resizeMechanism;
	}

	public int getResizeMechanism() {
		return resizeMechanism;
	}
}
